package com.cs.study.homework._0222;

public class Demo2 {
    public static void main(String[] args) {
        Person person;
        person = new Person() {
            @Override
            public void eat() {
                System.out.println("人都要吃米饭");
            }
        };
        person.eat();

        System.out.println("---------------");

        person = new SouthPerson("zs", 15);
        person.eat();
        if (person instanceof SouthPerson) {
            ((SouthPerson) person).swim();
            System.out.println(((SouthPerson) person).salary);
            ;
        }

        System.out.println("--------------------------");

        person = new NorthPerson("ls", 16);
        person.eat();
        if (person instanceof NorthPerson) {
            ((NorthPerson) person).drink();
            System.out.println(((NorthPerson) person).height);
        }
    }
}

abstract class Person {
    String name;
    int age;

    public abstract void eat();

    public Person() {
    }

    public Person(String name) {
        this.name = name;
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }
}

class SouthPerson extends Person {
    double salary;

    public SouthPerson(String name, int age) {
        super(name, age);
    }

    @Override
    public void eat() {
        System.out.println("南方人喜欢吃米饭");
    }

    public void swim() {
        System.out.println("swim");
    }
}

class NorthPerson extends Person {
    double height;

    public NorthPerson(String name, int age) {
        super(name, age);
    }

    @Override
    public void eat() {
        System.out.println("北方人喜欢吃面食");
    }

    public void drink() {
        System.out.println("drink");
    }
}



